<template>
	<el-table-column v-bind="$attrs" :min-width="minWidth" show-overflow-tooltip>
		<template #default="{ row, column }">
			{{ getMingCheng(row[column.property]) }}
		</template>
	</el-table-column>
</template>
<script lang="ts" setup>
// 基础资料id转名称mingcheng
import { getBasXueYeChanPinFeiYongMingCheng, getXueYePinZhongMingCheng, getOrgName, getBasXueYeLaiYuanList, getUserName } from '/@/stores/baseInfo/';
defineOptions({
	name: 'MkColumnBasEntity',
});

const props = defineProps({
	col: { // 宽度比例 0.1 到 6.0
		type: Number,
		default: 1,
	},
	entity: { // 实体名, 数据库表名
		type: String,
		require: true
	},
});

// 宽度以120px为1单位
const minWidth = computed(() => {
	return props.col * 120;
});

let list = [] as any[]

onMounted(async () => {
	switch (props.entity) {
		case 'BasXueYeLaiYuan': //血液来源
			list = await getBasXueYeLaiYuanList();
			break;
	}
})

const getMingCheng = (id: number | string) => {
	if (!props.entity) {
		return id;
	}

	let mingCheng = '';
	switch (props.entity) {
		case 'SysOrg':
			mingCheng = getOrgName(id as number);
			break;
		case 'BasXueYePinZhong': // 血液品种
			mingCheng = getXueYePinZhongMingCheng(id as number);
			break;
		case 'BasXueYeChanPinFeiYong': //产品收费名称
			mingCheng = getBasXueYeChanPinFeiYongMingCheng(id as number);
			break;
		case 'BasXueYeLaiYuan': //血液来源
			mingCheng = list.find((item) => item.id == id)?.mingCheng ?? '';
			break;
		case 'SysUser':
			mingCheng = getUserName(id as number)
			break
	}

	if (null == mingCheng || '' == mingCheng || undefined == mingCheng) {
		return id;
	}
	else {
		return mingCheng;
	}
}
</script>
